package PersistanceLayer;

import BusinessLayer.*;

import PersistanceLayer.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import jdbc.ConnectionToOracle;

public class EcueDAO extends DAO<Ecue> {

    private static final EcueDAO instance = new EcueDAO();

     /* Methode permettant de recuperer l'objet unique de type AnneeDAO
     */
    public final static EcueDAO getInstance() {
        return instance;
    }

    @Override
    public boolean create(Ecue obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Ecue obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Ecue ancien, Ecue nouveau) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Ecue find(Ecue obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Ecue obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Ecue> getListe() {

        	String libelleEcuee;
        	String volHoraire;
        	String codeMatiere;
        	String coeffMatiere;
        	
        	    	
        	ArrayList<Ecue> ensEcue = new ArrayList<Ecue>();

        	
        	try {
        		
        		java.sql.Statement state =this.connect.createStatement();
        		
    			ResultSet res = this.connect.createStatement()
    			.executeQuery("SELECT * FROM Ecue");
    		
    			
    			while(res.next()){	
    				
    				if(res.getObject(1) != null)
    					codeMatiere = res.getObject(1).toString();
    				else
    					codeMatiere = "";
    				
    				if(res.getObject(4) != null)
    					libelleEcuee = res.getObject(4).toString();
    				else
    					libelleEcuee = "";
    				
    				if(res.getObject(5) != null)
    					coeffMatiere = res.getObject(5).toString();
    				else
    					coeffMatiere = "";
    				
    				if(res.getObject(6) != null)
    					volHoraire = res.getObject(6).toString();
    				else
    					volHoraire = "";
    				
    				
    			ensEcue.add(new Ecue(codeMatiere, libelleEcuee, coeffMatiere, volHoraire));	
    				
    				
    			}
    			
    			state.close();
    			res.close();
    			
    			return ensEcue;
        	} catch (SQLException e) {
    			// 
        		
    			e.printStackTrace();
    			return null;
    		}
        	
        }
    
    public ArrayList<Ecue> getListe(String ue) {
    	String libelleEcuee;
    	String volHoraire;
    	String codeMatiere;
    	String coeffMatiere;
    	    	
    	ArrayList<Ecue> ensEcue = new ArrayList<Ecue>();

    	
    	try {
    		
    		java.sql.Statement state =this.connect.createStatement();
    		
    		
    		ResultSet res = this.connect.createStatement()
			.executeQuery("SELECT * from ecue " +
					"where codeue = '"+ ue +"'");
		
			
			while(res.next()){	
				
				if(res.getObject(1) != null)
					codeMatiere = res.getObject(1).toString();
				else
					codeMatiere = "";
				
				if(res.getObject(4) != null)
					libelleEcuee = res.getObject(4).toString();
				else
					libelleEcuee = "";
				
				if(res.getObject(5) != null)
					coeffMatiere = res.getObject(5).toString();
				else
					coeffMatiere = "";
				
				if(res.getObject(6) != null)
					volHoraire = res.getObject(6).toString();
				else
					volHoraire = "";
				
			ensEcue.add(new Ecue(codeMatiere, libelleEcuee, coeffMatiere, volHoraire));	
				
				
			}
			
			state.close();
			res.close();
			
			return ensEcue;
    	} catch (SQLException e) {
			// 
    		
			e.printStackTrace();
			return null;
		}
    	
    }



	@Override
	public String getNom(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean update(String a, String b, String c, String d) {
		// TODO Auto-generated method stub
		return false;
	}
    
   /* public static void main(String[] args){
		
    	Connection connexion;
    	EcueDAO ecue = new EcueDAO();
    	ArrayList<Ecue> listEcue = new ArrayList<Ecue>();
    	
    	connexion = ConnectionToOracle.getInstance();
    	listEcue=ecue.getListe("UEE");
    	System.out.println(listEcue.toString());
    	}*/
    




}